var opcoes_maps = {
  draggable: true
};
 
var MostraDirecao;
//var directionsDisplay = new google.maps.DirectionsRenderer(rendererOptions);;
var ServicoGoogle = new google.maps.DirectionsService();
var map;
 
function initialize() {
  MostraDirecao = new google.maps.DirectionsRenderer(opcoes_maps);
  // centralizando mapa
  var barra_mansa = new google.maps.LatLng(-22.547817,-44.171219);
  var mapOptions = {
    zoom:7,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    center: barra_mansa
  }
  map = new google.maps.Map(document.getElementById("mapa"), mapOptions);
  MostraDirecao.setMap(map);
  MostraDirecao.setPanel(document.getElementById("caminho"));
   
  var defaultBounds = new google.maps.LatLngBounds(
  new google.maps.LatLng(-22.547817,-44.171219));
   
 
  var input_origem = document.getElementById('origem');
  var options = {
  bounds: defaultBounds,
  types: ['geocode']
};
 
autocomplete1 = new google.maps.places.Autocomplete(input_origem, options);
 
  var input_destino = document.getElementById('destino');
  var options = {
  bounds: defaultBounds,
  types: ['geocode']
};
 
autocomplete2 = new google.maps.places.Autocomplete(input_destino, options);
 
}
 


// calculando rota
function calculaRota() {
	var origem = document.getElementById("origem").value;//{Estou aqui!!!}
	alert(origem);
	var destino = document.getElementById("destino").value;


	var coordenadas = [
	                  origem,
	                  destino
//	         	      new google.maps.LatLng(37.772323, -122.214897),
//	         	      new google.maps.LatLng(21.291982, -157.821856),
//	         	      new google.maps.LatLng(-18.142599, 178.431),
//	         	      new google.maps.LatLng(-27.46758, 153.027892)
	         	  ];

	var montaCaminho = new google.maps.Polyline({
	    path: coordenadas,// recebe o array de coordenadas
	    strokeColor: '#FF0000',//cor
	    strokeOpacity: 1.0,//opacidade
	    strokeWeight: 3 //espessura da linha
	  });

	montaCaminho.setMap(map);

   
   
//  var request = {
//    origin:origem,
//    destination:destino,
//    travelMode: google.maps.TravelMode.TRANSIT
//  };
//  ServicoGoogle.route(request, function(result, status) {
//    if (status == google.maps.DirectionsStatus.OK) {
//      MostraDirecao.setDirections(result);
//    }
//  });
}
